<?php
if(!isset($_SESSION['user'])){
redirect(LOGIN);
}



if($_GET['act']=='upload'){
	
	$data1['title']="Upload - Mong.vn";
	loadview('template/header_admin',$data1);
	loadview('user/upload_step',$data);
	loadview('template/footer_admin',$data);
	exit();
}

if($_SESSION['user']['upload']!=1){
	redirect(UPLOAD);
}
if($_GET['act']=='post_truyen'){

	$data1['title']="Đăng Chương Truyện";
	loadview('template/header_admin',$data1);
	loadview('user/post_truyen',$data);
	loadview('template/footer_admin',$data);
	exit();
}
if($_GET['act']=='post_truyen2'){
	if($_SESSION['user']['level']!=1){
	die();
	}
	$data1['title']="Update Truyện";
	loadview('template/header_admin',$data1);
	loadview('user/post_truyen_auto',$data);
	loadview('template/footer_admin',$data);
	exit();
}
if($_GET['act']=='post_image'){
		$model = new Model();
		$model->select = "id, name";
		$model->where = "(username = '" . $_SESSION['user']['username'] . "' or public=1) and type='image'";
		$model->order = "name ASC";
		$model->getdata('album');
		$data['albums'] = $model->fetchAll();
		
		$model->select = "id, name, p_id";
		$model->where = "image_type = 1";
		$model->order = "thutu ASC";
		$model->getdata('category');
		$resultArr = $model->fetchAll();
		
		recursive($resultArr, 0 , 1, $data['categories']);
		$data1['title']="Upload Ảnh - Mong.vn";
		loadview('template/header_admin',$data1);
		loadview('user/post_image',$data);
		loadview('template/footer_admin',$data);
		exit();

}

if($_GET['act']=='post_text'){
		$model = new Model();
		$model->select = "id, name";
		$model->order = "name ASC";
		$model->where = " (username = '" . $_SESSION['user']['username'] . "' or public=1) and type='blog'";
		$model->getdata('album');
		$data['albums'] = $model->fetchAll();
		
		$model->select = "id, name, p_id";
		$model->where = "text_type = 1";
		$model->order = "thutu ASC";
		$model->getdata('category');
		$resultArr = $model->fetchAll();
		
		if($_GET['id']){
			$model->select = "*";
			$model->where = "id = '" . intval($_GET['id']) . "'";
			$model->limit = 1;
			$model->order = "";
			$model->getdata('index_post');
			$indexPost = $model->fetchOne();
			
			
			if($indexPost){
				
				
				if($indexPost['username'] != $_SESSION['user']['username']){
					if($_SESSION['user']['level'] != 1 && $_SESSION['user']['level'] != 2){
						redirect(HOME . 'user/upload/text');
					}
				}
				
				$model->select = "*";
				$model->where = "id = '" . $indexPost['post_id'] . "'";
				$model->getdata('post_text');
				$postText = $model->fetchOne();
				if(!$postText) {
					redirect(HOME . 'user/upload/text');
				}
				
			}else{
				redirect(HOME . 'user/upload/text');
			}
			
			
			
			$data['postText'] = $postText;
		}
		
		recursive($resultArr, 0 , 1, $data['categories']);
		
		
		$data1['title']="Đăng Blog - Mong.vn";
		loadview('template/header_admin',$data1);
		loadview('user/post_text',$data);
		loadview('template/footer_admin',$data);
		exit();
}

if($_GET['act']=='post_video'){

		$model = new Model();

		$model->select = "id, name";
		$model->order = "name ASC";
		$model->where = " (username = '" . $_SESSION['user']['username'] . "' or public=1) and type='video'";
		$model->getdata('album');
		$data['albums'] = $model->fetchAll();
		
		$model->select = "id, name, p_id";
		$model->where = "video_type = 1";
		$model->order = "thutu ASC";
		$model->getdata('category');
		$resultArr = $model->fetchAll();
		
		recursive($resultArr, 0 , 1, $data['categories']);
		
		$data1['title']="Upload Video- Mong.vn";
		loadview('template/header_admin',$data1);
		loadview('user/post_video',$data);
		loadview('template/footer_admin',$data);
		exit();
}


?>
